(function () {
    //构造器
    function GanttCustom(config) {
        this.ganttCustom;
        this.elem = config.elem,//内容盒子
            this.tableRowWidth = config.tableRowWidth || 30,//右侧表格列宽度
            this.tableRowHeight = config.tableRowWidth || 25,//右侧表格列高度
            this.taskOpacity = config.taskOpacity || 0.5,//进度条背景颜色透明度
            this.taskColor = config.taskColor || '#3CB8D2',//进度条任务未完成颜色
            this.rateOpacity = config.rateOpacity || 0.7,//进度条进度颜色透明度
            this.rateColor = config.rateColor || '#299CB4',//进度条进度颜色
            this.startTime = config.startTime || dateDelDays(getCurrentDay(), 7),//任务开始日期
            this.endTime = config.endTime || nextMonthEndday(),//任务结束日期
            this.processText = config.processText || 'name,rate',//进度条上显示那些字段，逗号隔开
            this.showType = config.showType || 'day',//展示形式，day:日；month:月，jidu:季度，year:年 
            this.leftShowColNum = config.leftShowColNum || 1, // 左侧展示几列单位 ( 1 or 2) (默认1)
            this.isShowRateDiv = config.isShowRateDiv || 1, // 是否展示右侧内部实际进度条 (2不展示, 默认展示1)
            this.tableData = config.tableData || [],//表格数据
            this.dlclick = config.dlclick,
            this.resizeHandle = config.resizeHandle,
            this.dragHandle = config.dragHandle,
            this.initData(config);

        $('#mainGanttBox').attr('colnum', config.leftShowColNum);
    }

    var isDragFlg = false
    var rightClickObj = '', rightClickDate = new Date(),
        isOneDay = false, jiduMinDate, jiduMaxDate, minMonthDate, maxMonthDate, minYearDate, maxYearDate, selectedIcon
    var rightClickStartTime, rightClickEndTime, rightClickLeft, rightClickItem
    var taskBgColor, rateBgColor, startDateAll = [], endDateAll = []

    GanttCustom.prototype = {
        constructor: GanttCustom,
        // 获取数据中最小最大日期
        initData(config) {
            var _this = this;
            _this.$ele = $(config.elem)
            if (config.startTime || config.endTime) {
                _this.startTime = config.startTime
                _this.endTime = config.endTime
            } else {
                getDateFn(config.tableData)
                // 取所有任务的最小日期和最大日期
                _this.startTime = getDateMin(startDateAll)
                _this.endTime = getDateMax(endDateAll)
            }


            if (config.tableData && config.tableData.length > 0) {
                $('.showNoData').hide()
                _this.createDom()
                _this.createTimeTable()
                _this.initRightTable(_this)
            } else {
                _this.$ele.empty()
                if ($('.showNoData').length > 0) {
                    $('.showNoData').show()
                } else {
                    _this.$ele.append('<div class="showNoData" style="position:absolute;left:50%;transform:translateX(-50%);top:30%;font-size:16px;color:grey;">暂无数据</div>')
                }

            }
        },
        reload(newConfig) {
            var _this = this;
            let curTableData
            if (!!newConfig.tableData) {
                curTableData = newConfig.tableData
                _this.tableData = newConfig.tableData
            } else {
                curTableData = _this.tableData
            }
            if (newConfig.startTime || newConfig.endTime) {
                _this.startTime = newConfig.startTime
                _this.endTime = newConfig.endTime
            } else {
                getDateFn(curTableData)
                // 取所有任务的最小日期和最大日期
                _this.startTime = getDateMin(startDateAll)
                _this.endTime = getDateMax(endDateAll)
                // 取所有任务的最小日期和最大日期
                _this.startTime = getDateMin(startDateAll)
                _this.endTime = getDateMax(endDateAll)
            }
            _this.showType = newConfig.showType
            if (_this.showType == 'jidu' || _this.showType == 'year') {
                _this.tableRowWidth = 50
            } else {
                _this.tableRowWidth = 30
            }
            $('#latticeBox').css('background-size', _this.tableRowWidth + 'px 25px')


            if (curTableData && curTableData.length > 0) {
                $('.showNoData').hide()
                _this.createDom()
                _this.createTimeTable()
                _this.initRightTable(_this)
            } else {
                _this.$ele.empty()
                if ($('.showNoData').length > 0) {
                    $('.showNoData').show()
                } else {
                    _this.$ele.append('<div class="showNoData" style="position:absolute;left:50%;transform:translateX(-50%);top:30%;font-size:16px;color:grey;">暂无数据</div>')
                }
            }
        },
        showMenu(e) {
            var _this = this;
            let jlLeft = e.offsetX
            rightClickObj = e.currentTarget
            let juliLeftGezi = Math.floor(jlLeft / _this.tableRowWidth)

            let className = e.target.className
            let taskId, parentId, startTime, endTime, taskName, rightClickItem

            if (className.indexOf('taskDiv') != -1 || className.indexOf('oneNodeImg') != -1) {
                // 点击的进度条
                taskId = $(e.target).attr('taskid')
                parentId = $(e.target).attr('parentid')
                startTime = $(e.target).attr('starttime')
                endTime = $(e.target).attr('endtime')
                taskName = $(e.target).attr('taskname')
                rightClickItem = {
                    id: taskId,
                    parentId: parentId,
                    startTime: startTime,
                    endTime: endTime,
                    name: taskName
                }
            } else if (className.indexOf('rateDiv') != -1) {
                taskId = $(e.target).parent('.taskDiv').attr('taskid')
                parentId = $(e.target).parent('.taskDiv').attr('parentid')
                startTime = $(e.target).parent('.taskDiv').attr('starttime')
                endTime = $(e.target).parent('.taskDiv').attr('endtime')
                taskName = $(e.target).parent('.taskDiv').attr('taskname')
                rightClickItem = {
                    id: taskId,
                    parentId: parentId,
                    startTime: startTime,
                    endTime: endTime,
                    name: taskName
                }
            } else if (className.indexOf('task_progress_drag') != -1) {

            } else if ($(e.target).attr('class').indexOf('imgNode') != -1) {
                // 点击的图标
                taskId = $(e.target).parent('.oneNodeImg').attr('taskid')
                parentId = $(e.target).parent('.taskline').attr('parentid')
                startTime = $(e.target).parent('.oneNodeImg').attr('date')
                taskName = $(e.target).parent('.oneNodeImg').attr('taskname')
                rightClickItem = {
                    id: taskId,
                    parentId: parentId,
                    startTime: startTime,
                    endTime: startTime,
                    isIcon: true,
                    name: taskName,
                    iconUrl: ''
                }
            } else {
                // 点击空白处-新增-取点击处日期
                parentId = $(e.target).attr('parentid')
                if (_this.showType == 'day') {
                    rightClickDate = formatDateDorward(_this.startTime, juliLeftGezi)
                } else {
                    // 计算点击位置日期
                    if (_this.showType == 'month') {
                        juliLeftGezi = Math.floor(jlLeft / _this.tableRowWidth / 3)
                        let curMonth = addMonths(minMonthDate, juliLeftGezi)
                        let curMonthDays = getDaysInMonth(curMonth)
                        let diffJuLi = jlLeft % (_this.tableRowWidth * 3)
                        let day = diffJuLi * curMonthDays / _this.tableRowWidth / 3

                        let allMonths = getMonth(minMonthDate, curMonth)
                        let allDays = 0
                        allMonths.forEach((item, index) => {
                            if (index != allMonths.length - 1) {
                                allDays += Number(getDaysInMonth(item))
                            } else {
                                allDays += day - 1
                            }
                        })
                        rightClickDate = formatDateDorward(minMonthDate, allDays)
                    } else if (_this.showType == 'year' || _this.showType == 'jidu') {
                        let minLeftDate = _this.showType == 'year' ? minYearDate : _this.showType == 'jidu' ? jiduMinDate : ''
                        // 距离最左侧有几列，拖动后所在月份及其月份有多少天，计算当月前所有月分的天数加上当月的天数
                        let juliLeftColNums = Math.floor(jlLeft / _this.tableRowWidth)
                        let curMonth = addMonths(minLeftDate, juliLeftColNums)
                        let curMonthDays = getDaysInMonth(curMonth)
                        let diffJuLi = jlLeft % _this.tableRowWidth
                        let day = diffJuLi * curMonthDays / _this.tableRowWidth

                        let allMonths = getMonth(minLeftDate, curMonth)
                        let allDays = 0
                        allMonths.forEach((item, index) => {
                            if (index != allMonths.length - 1) {
                                allDays += Number(getDaysInMonth(item))
                            } else {
                                allDays += day - 1
                            }
                        })
                        rightClickDate = formatDateDorward(minLeftDate, allDays)
                    }
                }
                rightClickItem = {
                    startTime: rightClickDate,
                    endTime: rightClickDate,
                    parentId: parentId
                }
            }
            return rightClickItem
        },
        update(rightClickItem) {
            let divLeft, divWidth
            if (rightClickItem.isIcon) {//显示图例
                let objCall = this.computePosition(rightClickItem)
                if (this.showType != 'day') {
                    divLeft = objCall.divLeft - 7
                } else {
                    divLeft = objCall.divLeft + this.tableRowWidth / 2 - 7
                }
                $('.oneNodeImg' + rightClickItem.id).css('left', divLeft)
                $('.oneNodeImg' + rightClickItem.id).attr('date', rightClickItem.startTime)
                $('.oneNodeImg' + rightClickItem.id).attr('taskname', rightClickItem.name)

                // 	let html=`<div class="oneNodeImg oneNodeImg${selfId}" date="${curTime}" taskname="${taskName}" taskId="${selfId}" parentId="${parentId}" style="width:14px;height:25px;line-height:25px;left:${divLeft}px">
                // 						<img class="imgNode" src="${iconUrl}" style="width:14px;height:14px;">
                // 						</div>`
                // 	$(rightClickObj).append(html)
            } else {
                let objCall = this.computePosition(rightClickItem)
                divLeft = objCall.divLeft
                divWidth = objCall.divWidth

                $('.taskDiv' + rightClickItem.id).css({'left': divLeft, 'width': divWidth})
                $('.taskDiv' + rightClickItem.id).attr('starttime', rightClickItem.startTime)
                $('.taskDiv' + rightClickItem.id).attr('endtime', rightClickItem.endTime)
                $('.taskDiv' + rightClickItem.id).attr('taskname', rightClickItem.name)
                let rate = $('.rateDiv' + rightClickItem.id).attr('oldrate') || 0
                $('.taskDiv' + rightClickItem.id).attr('data-content', rightClickItem.name + '  ' + (rate == 0 ? '' : rate + '%'))


                // let html=`<div class="taskDiv taskDiv${selfId}" title="${taskName}" taskname="${taskName}" data-content="${taskName + '   ' + (obj.rate ? obj.rate +'%' : '')}" taskId="${selfId}" parentId="${parentId}"  startTime="${sTime}" endTime="${eTime}" style="left:${divLeft}px;width:${divWidth}px;">
                // 				<div class="rateDiv rateDiv${selfId}" taskId="${selfId}" style="width:0px;"></div>
                // 			</div>`
                // 			// 隐藏进度条拖动
                // 			// <div class="drapBox drapBox${selfId}" taskId='${selfId}' style="width:${divWidth+7}px;left:${divLeft}px;">
                // 			// 	<div class="task_progress_drag task_progress_drag${selfId}" taskId="${selfId}"></div>
                // 			// </div>
                // $(rightClickObj).append(html)
            }
        },
        add(rightClickItem) {
            let divLeft, divWidth
            //新增默认可拖可缩放
            rightClickItem.isDrag = true, rightClickItem.isResize = true
            if (rightClickItem.isIcon) {//显示图例
                let objCall = this.computePosition(rightClickItem)
                if (this.showType != 'day') {
                    divLeft = objCall.divLeft - 7
                } else {
                    divLeft = objCall.divLeft + this.tableRowWidth / 2 - 7
                }

                let html = `<div class="oneNodeImg oneNodeImg${rightClickItem.id}" isdrag="${rightClickItem.isDrag}" date="${rightClickItem.startTime}" taskname="${rightClickItem.name}" taskId="${rightClickItem.id}" parentId="${rightClickItem.parentId}" style="width:14px;height:25px;line-height:25px;left:${divLeft}px">
									<img class="imgNode" src="${rightClickItem.iconUrl}" style="width:14px;height:14px;">
									</div>`
                $(rightClickObj).append(html)
            } else {
                let objCall = this.computePosition(rightClickItem)
                divLeft = objCall.divLeft
                divWidth = objCall.divWidth
                let html = `<div class="taskDiv taskDiv${rightClickItem.id}" title="${rightClickItem.name}" isdrag="${rightClickItem.isDrag}" isresize="${rightClickItem.isResize}" taskname="${rightClickItem.name}" data-content="${rightClickItem.name + '   ' + (rightClickItem.rate ? rightClickItem.rate + '%' : '')}" taskId="${rightClickItem.id}" parentId="${rightClickItem.parentId}"  startTime="${rightClickItem.startTime}" endTime="${rightClickItem.endTime}" style="left:${divLeft}px;width:${divWidth}px;">
								<div class="rateDiv rateDiv${rightClickItem.id}" taskId="${rightClickItem.id}" style="width:0px;"></div>
							</div>`
                // 隐藏进度条拖动
                // <div class="drapBox drapBox${selfId}" taskId='${selfId}' style="width:${divWidth+7}px;left:${divLeft}px;">
                // 	<div class="task_progress_drag task_progress_drag${selfId}" taskId="${selfId}"></div>
                // </div>
                $(rightClickObj).append(html)
            }
            this.initEvent()
        },
        getTableMinAndMaxDate() {
            //获取右侧区域最小日期、最大日期
            let setMinDate, setMaxDate
            if (this.showType == 'month') {
                setMinDate = minMonthDate
                setMaxDate = maxMonthDate
            } else if (this.showType == 'year') {
                setMinDate = minYearDate
                setMaxDate = maxYearDate
            } else if (this.showType == 'jidu') {
                setMinDate = jiduMinDate
                setMaxDate = jiduMaxDate
            } else {
                setMinDate = this.startTime
                setMaxDate = this.endTime
            }
            return {tableMinDate: setMinDate, tableMaxDate: setMaxDate}
        },
        // 基础的dom
        createDom() {
            var _this = this;
            _this.$ele.empty()
            let html = '';
            let left_Col_html = '';
            // gantt图修改js
            // 展示2列单位
            if (this.leftShowColNum == 2) left_Col_html = '<div class="rwName unitName2">参研单位</div>';
            html += `<div class="ganttContainer">
				<img src="/plugins/ganttCustom/qh2.png" class="colCollops" onclick="changeCol(event)"/>
				<div class="leftTable">
					<div class="tableTitle">
						<div class="rwName">任务</div>
						<div class="rwName unitName">责任单位</div>
                        ${left_Col_html}
					</div>
					<div class="leftTableTop">
						<table id="treeTable">
						</table>
					</div>
				</div>
				<div id="rightTable">
					<div id="dateTable">
						
					</div>
					
					<div id="mainTable" style="position: relative;height: calc(100% - 85px);">
						<div id="dataList" class="clearfix" style="position:absolute;width: 100%;height: 100%;">
							
						</div>
						<div id="latticeBox" style="border-right: 1px solid rgba(255, 255, 255, 0) ;">
						    <ul></ul>
						</div>
					</div>
				</div>
			</div>`
            _this.$ele.append(html)
            $('#latticeBox').css('background-size', _this.tableRowWidth + 'px 25px')
        },
        createTimeTable() {
            var _this = this;
            let sTime = _this.startTime, eTime = _this.endTime
            _this.$ele.find("#dateTable").empty();
            // 格子清空
            _this.$ele.find("#latticeBox").find('ul').empty();
            var yearMonthStr = "";
            var daysStr = "";
            var daysIndex = 0;
            var weekStr = "";
            var cellDiv = "";
            //昨天的年份
            var yesterdayYear = "";
            //昨天的月份
            var yesterdayMonth = "";
            //昨天的周
            var yesterdayWeek = "";
            //创建表格格子线条
            var bgTabStr = "";
            let datasDate = []

            if (_this.showType == 'day') {
                let allDays = getDiffDate(sTime, eTime)
                allDays.forEach(item => {
                    datasDate.push({
                        calendarDate: item
                    })
                })
                for (var k = 0; k < datasDate.length; k++) {
                    var dataSub = datasDate[k].calendarDate.substring(0, 10);
                    // dateArr[0] 年 dateArr[1] 月 dateArr[2] 日
                    var dateArr = dataSub.split('-');
                    var week = getWeekNum(dataSub);
                    //昨天的月份与今天的月份对比
                    if (k > 0) {
                        daysIndex++;
                        if (dateArr[1] != yesterdayMonth) {
                            // yearMonthStr += '<th colspan="' + daysIndex + '">' + yesterdayYear + '年' + yesterdayMonth + '月 </th>';
                            // yearMonthStr += '<th colspan="' + daysIndex + '">' + yesterdayMonth.replace(/^0/,"") + '月 </th>';
                            if (daysIndex <= "3") {
                                yearMonthStr += '<th colspan="' + daysIndex + '">' + yesterdayMonth.replace(/^0/, "") + ' </th>';
                            } else {
                                yearMonthStr += '<th colspan="' + daysIndex + '">' + yesterdayMonth.replace(/^0/, "") + '月(' + yesterdayYear + '年) </th>';
                            }
                            daysIndex = 0;
                        }
                        if (k == datasDate.length - 1) {
                            // yearMonthStr += '<th colspan="' + daysIndex + 1 + '">' + yesterdayYear + '年' + yesterdayMonth + '月 </th>';
                            // yearMonthStr += '<th colspan="' + daysIndex + 1 + '">' + yesterdayYear + '年' +   yesterdayMonth.replace(/^0/,"") + '月 </th>';
                            if (daysIndex == "0") {
                                yearMonthStr += '<th colspan="' + (Number(daysIndex) + 1) + '">' + (Number(yesterdayMonth.replace(/^0/, "")) + 1) + ' </th>';
                            } else if (daysIndex <= "2" && daysIndex >= "1") {
                                yearMonthStr += '<th colspan="' + (Number(daysIndex) + 1) + '">' + yesterdayMonth.replace(/^0/, "") + ' </th>';
                            } else {
                                yearMonthStr += '<th colspan="' + (Number(daysIndex) + 1) + '">' + yesterdayYear + '年' + yesterdayMonth.replace(/^0/, "") + '月 </th>';
                            }

                        }
                    }

                    daysStr += '<td  class="' + dataSub + '">' + dateArr[2] + ' </td>';
                    weekStr += '<td>' + getWeek(dataSub) + ' </td>';
                    cellDiv += '<td class="' + dataSub + '"></td>';

                    if (getWeek(dataSub) == '六' || getWeek(dataSub) == '日') {
                        bgTabStr = bgTabStr + '<li class="weekCol"></li>';
                    } else {
                        bgTabStr = bgTabStr + '<li></li>';
                    }
                    //存昨天的年份
                    yesterdayYear = dateArr[0];
                    //存昨天的月份
                    yesterdayMonth = dateArr[1];
                    //存昨天的周
                    yesterdayWeek = week;

                }
                _this.$ele.find("#dateTable").append('<thead><tr>' + yearMonthStr + '</tr></thead>');
                _this.$ele.find("#dateTable").append('<tbody ><tr>' + daysStr + '</tr><tr>' + weekStr + '</tr></tbody >');

                //格子线条数量
                _this.$ele.find("#latticeBox ul").append(bgTabStr);
                $('#dateTable').css('width', 'auto')
            } else if (_this.showType == 'month') {
                let monthLine = ''
                // 按月
                let allMonth = getMonth(sTime, eTime)
                allMonth.forEach(item => {
                    datasDate.push({
                        calendarDate: item
                    })
                })
                // 显示的区域最小最大日期
                minMonthDate = allMonth[0] + '-' + '01'
                let days = getDaysInMonth(allMonth[allMonth.length - 1])
                maxMonthDate = allMonth[allMonth.length - 1] + '-' + days

                daysIndex = 0
                if (datasDate.length > 0) {
                    yesterdayYear = datasDate[0].calendarDate.substring(0, 4)
                }

                datasDate.forEach((item, index) => {
                    let dataSub = item.calendarDate.substring(0, 10);
                    // dateArr[0] 年 dateArr[1] 月 dateArr[2] 日
                    let dateArr = dataSub.split('-');


                    if (yesterdayYear != dateArr[0]) {
                        yearMonthStr += '<th colspan="' + Number(daysIndex) + '" style="font-size:14px;">' + yesterdayYear + '年' + ' </th>'
                        daysIndex = 1;
                    } else {
                        daysIndex++
                    }
                    if (index == datasDate.length - 1) {
                        yearMonthStr += '<th colspan="' + Number(daysIndex) + '" style="font-size:14px;">' + dateArr[0] + '年' + ' </th>'
                    }
                    monthLine += '<th style="width:' + 3 * _this.tableRowWidth + 'px!important;max-width:' + 3 * _this.tableRowWidth + 'px!important;height:40px;font-size:14px;">' + item.calendarDate.substring(5, 7) + '月 </th>';
                    //存昨天的年份
                    yesterdayYear = dateArr[0];
                    // 每一周加3个格子
                    for (let i = 0; i < 3; i++) {
                        if (i == 2) {
                            bgTabStr = bgTabStr + '<li class="monthLineRow"></li>'
                        } else {
                            bgTabStr = bgTabStr + '<li></li>';
                        }
                    }
                })
                _this.$ele.find("#dateTable").append('<thead><tr>' + yearMonthStr + '</tr><tr>' + monthLine + '</tr></thead>');
                // 格子
                _this.$ele.find("#latticeBox ul").append(bgTabStr);
                $('#dateTable').css('width', datasDate.length * 3 * _this.tableRowWidth + 1)

            } else if (_this.showType == 'jidu') {
                let jiduYear = '', mjiduLine = ''
                let minJidu = Math.floor(Number(sTime.substring(5, 7)) / 3) //开始日期所在季度为此结果加1
                let firstYearHasJiduNum = 4 - minJidu//开始年份有几个季度
                let maxEndJidu = Math.ceil(Number(eTime.substring(5, 7)) / 3) //结束日期所在季度

                let years = getYearsInRange(sTime, eTime)
                let colspanNum = 4
                if (years.length > 1) {
                    // 跨年
                    let fistColspan = firstYearHasJiduNum

                    years.forEach((item, index) => {
                        if (index == 0) {
                            let setNu = minJidu
                            // 第一年
                            jiduYear += '<th colspan="' + Number(4 - minJidu) + '" style="font-size:14px;">' + item + '年' + ' </th>'
                            for (let i = 0; i < 4 - minJidu; i++) {
                                setNu++
                                mjiduLine += '<th style="width:' + 3 * _this.tableRowWidth + 'px!important;max-width:' + 3 * _this.tableRowWidth + 'px!important;height:40px;font-size:14px;">' + '第' + setNu + '季度' + '</th>'
                            }
                        } else if (index == years.length - 1) {
                            // 最后一年
                            jiduYear += '<th colspan="' + maxEndJidu + '" style="font-size:14px;">' + item + '年' + ' </th>'
                            for (let i = 0; i < maxEndJidu; i++) {
                                mjiduLine += '<th style="width:' + 3 * _this.tableRowWidth + 'px!important;max-width:' + 3 * _this.tableRowWidth + 'px!important;height:40px;font-size:14px;">' + '第' + Number(i + 1) + '季度' + '</th>'
                            }
                        } else {
                            jiduYear += '<th colspan="4" style="font-size:14px;">' + item + '年' + ' </th>'
                            for (let i = 1; i < 5; i++) {
                                mjiduLine += '<th style="width:' + 3 * _this.tableRowWidth + 'px!important;max-width:' + 3 * _this.tableRowWidth + 'px!important;height:40px;font-size:14px;">' + '第' + i + '季度' + '</th>'
                            }
                        }
                    })
                } else {
                    // 同一年
                    colspanNum = maxEndJidu - minJidu
                    let setNu = minJidu
                    years.forEach((item, index) => {
                        jiduYear += '<th colspan="' + colspanNum + '" style="font-size:14px;">' + item + '年' + ' </th>'
                        for (let i = 0; i < colspanNum; i++) {
                            setNu++
                            mjiduLine += '<th style="width:' + 3 * _this.tableRowWidth + 'px!important;max-width:' + 3 * _this.tableRowWidth + 'px!important;height:40px;font-size:14px;">' + '第' + setNu + '季度' + '</th>'
                        }
                    })
                }
                let startTimeMinMonth = minJidu * 3 + 1 < 10 ? '0' + Number(minJidu * 3 + 1) : minJidu * 3 + 1
                let endTimeMaxMonth = maxEndJidu * 3 < 10 ? '0' + Number(maxEndJidu * 3) : maxEndJidu * 3
                // 当前左侧开始位置最小日期
                jiduMinDate = new Date(sTime).getFullYear() + '-' + startTimeMinMonth + '-' + '01'
                // 当前右侧结束位置最大日期
                let lastMonthDays = getDaysInMonth(new Date(eTime).getFullYear() + '-' + endTimeMaxMonth)
                jiduMaxDate = new Date(eTime).getFullYear() + '-' + endTimeMaxMonth + '-' + lastMonthDays

                _this.$ele.find("#dateTable").append('<thead><tr>' + jiduYear + '</tr><tr>' + mjiduLine + '</tr></thead>');
                $('#dateTable').css('width', years.length * _this.tableRowWidth * 12 + 1)

            } else if (_this.showType == 'year') {
                let years = getYearsInRange(sTime, eTime)
                minYearDate = years[0] + '-' + '01' + '-' + '01'
                maxYearDate = years[years.length - 1] + '12' + '31'
                let jiduYear = ''
                years.forEach((item, index) => {
                    jiduYear += '<th style="font-size:14px;width:' + _this.tableRowWidth * 12 + 'px;max-width:none;height:60px;">' + item + '年' + ' </th>'

                })
                _this.$ele.find("#dateTable").append('<thead><tr>' + jiduYear + '</tr></thead>');
                $('#dateTable').css('width', years.length * _this.tableRowWidth * 12 + 1)
            }
            $('#dateTable td').css({'min-width': _this.tableRowWidth, 'max-width': _this.tableRowWidth})
            $('#mainTable #latticeBox ul li').css('width', _this.tableRowWidth)
            _this.$ele.find("#lineBox").css("width", $("#dateTable").css("width"));
            _this.$ele.find("#latticeBox").css("width", parseInt($("#dateTable thead").css("width")) + 2);
        },
        initRightTable() {
            var _this = this
            if (_this.tableData.length > 0) {
                $('#leftTableBody').empty()
                $('#dataList').empty()
                $('#treeTable').empty()
                _this.fnPage(_this.tableData, '')
                _this.$ele.find(".taskline").css("width", parseInt($("#dateTable thead").css("width")) + 2);//宽度不够缩放会偏移
                // 操作区域要和日期的宽度一致
                $('#dataList').width($('#dateTable thead').width())
                _this.initEvent()
            }
        },
        initEvent() {
            var _this = this
            // 监听左侧展开收缩
            $('.firstCol span').click(function () {
                let id = $(this).parents('.node-title').attr('id')
                let className = $($(this)[0]).attr('class')

                // 切换展开缩放图标
                if (className.indexOf('addPicZK') != -1) {
                    $(this).removeClass('addPicZK')
                    $(this).addClass('addPicZD')
                    $('.showModel' + id).hide()
                } else if (className.indexOf('addPicZD') != -1) {
                    $(this).removeClass('addPicZD')
                    $(this).addClass('addPicZK')
                    $('.showModel' + id).show()
                }

            })
            // 双击查看详情
            $(document).on('dblclick', function (e) {
                let className = $(e.target).attr('class')
                let taskId = $(e.target).attr('taskid')
                if (className.indexOf('rateDiv') != -1 || className.indexOf('taskDiv') != -1) {
                    // _this.dlclick(taskId)

                }
            })
            // 显示拖动进度图标
            _this.$ele.find('.drapBox').mouseover(function () {
                let taskId = $(this).attr('taskid')
                let rateDivWidth = $('.rateDiv' + taskId).width()
                // 其他都隐藏
                if (!isDragFlg) {
                    $('.task_progress_drag').hide()
                    $('.task_progress_drag' + taskId).css({'left': rateDivWidth + 'px', 'display': 'block'})
                }
            })
            _this.$ele.find('.taskDiv').mouseover(function () {
                let taskId = $(this).attr('taskid')
                let rateDivWidth = $('.rateDiv' + taskId).width()

                if (!isDragFlg) {
                    $('.task_progress_drag' + taskId).css({
                        'left': rateDivWidth + 'px',
                        'display': 'block',
                        'pointer-events': 'auto'
                    })
                }
            })
            // 隐藏进度拖动图标
            _this.$ele.find('.oneNodeImg').mouseover(function () {
                $('.task_progress_drag').css({'display': 'none'})

            })
            _this.$ele.find('.taskDiv').mouseleave(function () {
                let taskId = $(this).attr('taskid')
                // 在拖动时不隐藏
                if (!isDragFlg) {
                    $('.task_progress_drag').hide()
                }

                $('.drapBox' + taskId).css({'pointer-events': 'none'})
            })
            // 隐藏拖动进度图标
            _this.$ele.find('.drapBox').each(function () {
                $(this).mouseleave(function () {
                    let taskId = $(this).attr('taskid')
                    if (!isDragFlg) {
                        $('.task_progress_drag' + taskId).css({'display': 'none'})
                    }
                })
            })

            // 拖动进度图标拖动事件
            _this.$ele.find('.task_progress_drag').each(function () {
                let taskId = $(this).attr('taskid')

                $(this).draggable({
                    containment: ".drapBox" + taskId,
                    axis: 'x',
                    drag: function (event, ui) {
                        // 让进度rateDiv宽度跟着变，拖的宽度
                        $('.rateDiv' + taskId).css('width', ui.position.left + 'px')
                        isDragFlg = true
                    }, stop: function (event, ui) {

                        let parentWidth = $('.taskDiv' + taskId).width()
                        let curWidth = $('.rateDiv' + taskId).width()
                        // 算出比例
                        let rate = Math.round(curWidth / parentWidth * 100) + '%'
                        tip_index = layer.tips(rate, $('.rateDiv' + taskId), {
                            tips: [1, "#22cc9b"],
                            time: 800
                        });
                        isDragFlg = false
                        // 存实时的进度
                        $('.rateDiv' + taskId).attr('oldrate', Math.round(curWidth / parentWidth * 100))

                    }
                })

            })
            // 单个图标的拖动
            _this.$ele.find('.oneNodeImg').each(function () {

                let parentId = $(this).attr('parentid')
                let taskId = $(this).attr('taskid')
                let isDrag = $(this).attr('isdrag')
                if (isDrag === 'true') {
                    $(this).draggable({
                        containment: ".taskline" + parentId,
                        axis: 'x',
                        grid: [_this.tableRowWidth, 25],
                        drag: function (event, ui) {
                            isDragFlg = true
                        }, stop: function (event, ui) {
                            let curLineWidth = $('.taskline' + parentId).width()
                            if (ui.position.left >= curLineWidth) {
                                ui.position.left = curLineWidth - 9
                            }
                            $(this).css('left', ui.position.left)
                            let myStartTime = $(this).attr('date')
                            // 拖动了
                            if ((ui.position.left - ui.originalPosition.left) != 0) {
                                let curStartTime
                                let dragJL = Number((ui.position.left - ui.originalPosition.left) / _this.tableRowWidth)
                                if (_this.showType != 'day') {
                                    if (_this.showType == 'month') {
                                        //拖动后的大致月份，7是三角形一半宽度
                                        let juliLeftColNums = Math.floor(ui.position.left / _this.tableRowWidth / 3)
                                        let curMonth = addMonths(minMonthDate, juliLeftColNums)
                                        let curMonthDays = getDaysInMonth(curMonth)
                                        let diffJuLi = ui.position.left % (_this.tableRowWidth * 3) + 7
                                        let day = diffJuLi * curMonthDays / _this.tableRowWidth / 3

                                        let allMonths = getMonth(minMonthDate, curMonth)
                                        let allDays = 0
                                        allMonths.forEach((item, index) => {
                                            if (index != allMonths.length - 1) {
                                                allDays += Number(getDaysInMonth(item))
                                            } else {
                                                allDays += day - 1
                                            }
                                        })
                                        curStartTime = formatDateDorward(minMonthDate, allDays)
                                    } else if (_this.showType == 'year' || _this.showType == 'jidu') {
                                        let minLeftDate = _this.showType == 'year' ? minYearDate : _this.showType == 'jidu' ? jiduMinDate : ''
                                        // 距离最左侧有几列，拖动后所在月份及其月份有多少天，计算当月前所有月分的天数加上当月的天数
                                        let juliLeftColNums = Math.floor(ui.position.left / _this.tableRowWidth)
                                        let curMonth = addMonths(minLeftDate, juliLeftColNums)
                                        let curMonthDays = getDaysInMonth(curMonth)
                                        let diffJuLi = ui.position.left % _this.tableRowWidth + 7
                                        let day = diffJuLi * curMonthDays / _this.tableRowWidth

                                        let allMonths = getMonth(minLeftDate, curMonth)
                                        let allDays = 0
                                        allMonths.forEach((item, index) => {
                                            if (index != allMonths.length - 1) {
                                                allDays += Number(getDaysInMonth(item))
                                            } else {
                                                allDays += day - 1
                                            }
                                        })
                                        curStartTime = formatDateDorward(minLeftDate, allDays)
                                    }

                                } else {
                                    let myStartTime = $(this).attr('date')
                                    curStartTime = formatDateDorward(myStartTime, dragJL)
                                }

                                if (_this.dragHandle) {
                                    let obj = {
                                        taskId,
                                        startTime: curStartTime,
                                        endTime: curStartTime
                                    }
                                    // 进度跟踪 - 拖动里程碑 调用
                                    _this.dragHandle(obj)
                                }
                                
                                // 拖动后实际的开始时间结束时间存起来
                                $(this).attr('date', curStartTime)
                            }

                            isDragFlg = false
                        }
                    })
                }

            })
            // 每个任务条的起始时间的拖动,缩放
            _this.$ele.find('.taskDiv').each(function () {
                let parentId = $(this).attr('parentid')
                let taskId = $(this).attr('taskid')
                let isDrag = $(this).attr('isdrag')
                let isResize = $(this).attr('isresize')

                let startDragFlg = false, endDragFlg = false, levelOneId, minTime, maxTime, myStartTime, myEndTime,
                    updateStartTime, updateEndTime, startDrag, myId
                // 每个任务只能在该任务行拖动，拖动grid最小为1列
                if (isResize === 'true') {
                    $(this).resizable({
                        containment: ".taskline" + parentId,
                        handles: 'e,w',
                        grid: [_this.tableRowWidth, 15],
                        maxHeight: 15,
                        cancel: 'input,textarea,button,select,option',
                        minWidth: _this.tableRowWidth,
                        resize: function (event, ui) {
                            isDragFlg = true
                            // 拖动时保持原来的进度比例
                            let rateDivWidthNew

                            let oldRate = $(this).find('.rateDiv').attr('oldrate')

                            let taskDivWidth = $(this).width()

                            if (oldRate == '100') {
                                // $(this).children('.rateDiv').width(taskDivWidth)
                                rateDivWidthNew = taskDivWidth
                            } else {
                                rateDivWidthNew = taskDivWidth * oldRate / 100
                                // $(this).children('.rateDiv').width(rateDivWidthNew)
                            }

                            // 找到该拖动块的一级父id
                            levelOneId = $(ui.helper[0]).attr('parentid')

                            myId = $(ui.helper[0]).attr('taskid')
                            myStartTime = $(ui.helper[0]).attr('starttime')

                            myEndTime = $(ui.helper[0]).attr('endtime')
                            // 开始时间拖动了几天,负数就是向左,正数向右拖动
                            startDrag = (ui.position.left - ui.originalPosition.left) / _this.tableRowWidth

                            if (startDrag != 0) {
                                startDragFlg = true
                            } else {
                                startDragFlg = false
                            }
                            // 当前日期拖动后的日期
                            updateStartTime = formatDateDorward(myStartTime, startDrag)

                            // 结束时间拖动了几天
                            if (ui.position.left == ui.originalPosition.left) {
                                endDragFlg = true
                                // 正数就是向右拖,负数向左
                                let endDrag = (ui.size.width - ui.originalSize.width) / _this.tableRowWidth

                                updateEndTime = formatDateDorward(myEndTime, endDrag)
                            } else {
                                endDragFlg = false
                            }

                            // 拖动盒子的left和宽及时更新，事件放开
                            $('.drapBox' + taskId).css({
                                'left': ui.position.left + 'px',
                                'width': taskDivWidth + 7 + 'px'
                            })
                            $('.task_progress_drag' + taskId).css({left: rateDivWidthNew + 'px'})


                        }, stop: function (event, ui) {
                            // 紧贴线移动
                            let left = $(this).css('left').replace('px', '')
                            let setLeft = ui.originalPosition.left, setWidth = ui.originalSize.width, isMoveLeft = false
                            // 拖动后的宽度要正好吸附线
                            if (ui.position.left == ui.originalPosition.left) {
                                isMoveLeft = false
                                // 拖的是右侧
                                // 进度条尾部的left值
                                let rightLeft = ui.originalPosition.left + ui.size.width
                                if (rightLeft % _this.tableRowWidth > _this.tableRowWidth / 2) {
                                    setWidth = Math.floor(rightLeft / _this.tableRowWidth) * _this.tableRowWidth + _this.tableRowWidth - ui.originalPosition.left + 1
                                } else {
                                    setWidth = Math.floor(rightLeft / _this.tableRowWidth) * _this.tableRowWidth - ui.originalPosition.left + 1
                                }
                                $(ui.helper[0]).css('width', setWidth)
                                // 更新进度占比宽度
                                let oldRate = $('.rateDiv' + taskId).attr('oldrate')
                                rateWidth = setWidth * oldRate / 100
                                $('.rateDiv' + taskId).css('width', rateWidth)
                            } else {
                                isMoveLeft = true
                                // 拖得是左侧,超出半个
                                if (left % _this.tableRowWidth > _this.tableRowWidth / 2) {
                                    setLeft = Math.floor(left / _this.tableRowWidth) * _this.tableRowWidth + _this.tableRowWidth
                                } else {
                                    setLeft = Math.floor(left / _this.tableRowWidth) * _this.tableRowWidth
                                }

                                if (setLeft < 0) {
                                    setLeft = 0
                                }
                                // 拖动吸附后计算进度条宽度
                                if (left < ui.originalPosition.left) {
                                    setWidth = ui.originalSize.width + ui.originalPosition.left - setLeft
                                } else {
                                    setWidth = ui.originalSize.width - (setLeft - ui.originalPosition.left)
                                }
                                $(ui.helper[0]).css('left', setLeft)
                                $(ui.helper[0]).css('width', setWidth)
                                // 更新进度条拖动图标位置
                                $('.drapBox' + taskId).css('left', setLeft)
                                // 更新进度占比宽度
                                let oldRate = $('.rateDiv' + taskId).attr('oldrate')
                                rateWidth = setWidth * oldRate / 100
                                $('.rateDiv' + taskId).css('width', rateWidth)
                            }
                            // 计算拖动后的日期
                            let oldStartTime = $(ui.helper[0]).attr('starttime')
                            let oldEndTime = $(ui.helper[0]).attr('endtime')

                            let curStartTime, curEndTime
                            if (_this.showType == 'month') {
                                // 距离前面有几个月,3列为一个月,1列为10天
                                if (isMoveLeft) {
                                    // 拖动左侧,结束时间不变
                                    curEndTime = oldEndTime
                                    curStartTime = addMonths(minMonthDate, Math.floor(setLeft / _this.tableRowWidth / 3)).substring(0, 7)
                                    let duochuCol = setLeft / _this.tableRowWidth % 3

                                    if (duochuCol == 0) {
                                        curStartTime = curStartTime + '-' + '01'
                                    } else if (duochuCol == 1) {
                                        curStartTime = curStartTime + '-' + '11'
                                    } else if (duochuCol == 2) {
                                        curStartTime = curStartTime + '-' + '21'
                                    }
                                } else {
                                    // 拖动右侧,开始时间不变
                                    curStartTime = oldStartTime
                                    curEndTime = addMonths(minMonthDate, Math.ceil((setLeft + setWidth - 1) / _this.tableRowWidth / 3) - 1).substring(0, 7)
                                    let duochuCol = Math.floor((setLeft + setWidth - 1) / _this.tableRowWidth % 3)
                                    let curMonthHasDays = getDaysInMonth(curEndTime)

                                    if (duochuCol == 0) {
                                        curEndTime = curEndTime + '-' + curMonthHasDays
                                    } else if (duochuCol == 1) {
                                        curEndTime = curEndTime + '-' + '10'
                                    } else if (duochuCol == 2) {
                                        curEndTime = curEndTime + '-' + '20'
                                    }
                                }

                            } else if (_this.showType == 'jidu') {
                                if (isMoveLeft) {
                                    // 拖动左侧,结束时间不变
                                    curEndTime = oldEndTime
                                    // 距离前面有几个月,3列为一个季度,1列一个月
                                    curStartTime = addMonths(jiduMinDate, Math.floor(setLeft / _this.tableRowWidth)).substring(0, 7)
                                    curStartTime = curStartTime + '-' + '01'
                                } else {
                                    // 拖动右侧,开始时间不变
                                    curStartTime = oldStartTime
                                    curEndTime = addMonths(jiduMinDate, Math.ceil((setLeft + setWidth - 1) / _this.tableRowWidth) - 1).substring(0, 7)
                                    let curMonthHasDays = getDaysInMonth(curEndTime)
                                    curEndTime = curEndTime + '-' + curMonthHasDays
                                }
                            } else if (_this.showType == 'year') {

                                if (isMoveLeft) {
                                    // 拖动左侧,结束时间不变
                                    curEndTime = oldEndTime
                                    // 距离前面有几个月,3列为一个季度,1列一个月
                                    curStartTime = addMonths(minYearDate, Math.floor(setLeft / _this.tableRowWidth)).substring(0, 7)
                                    curStartTime = curStartTime + '-' + '01'
                                } else {
                                    // 拖动右侧,开始时间不变
                                    curStartTime = oldStartTime
                                    curEndTime = addMonths(minYearDate, Math.ceil((setLeft + setWidth - 1) / _this.tableRowWidth) - 1).substring(0, 7)
                                    let curMonthHasDays = getDaysInMonth(curEndTime)
                                    curEndTime = curEndTime + '-' + curMonthHasDays
                                }
                            }

                            if (_this.showType == 'day') {
                                // 每次结束后更新dom上的属性,移动左边就更新开始时间，右边更新结束时间
                                if (startDragFlg) {
                                    $(ui.helper[0]).attr('starttime', updateStartTime)
                                }
                                if (endDragFlg) {
                                    $(ui.helper[0]).attr('endtime', updateEndTime)
                                }
                            } else {
                                $(ui.helper[0]).attr('starttime', curStartTime)
                                $(ui.helper[0]).attr('endtime', curEndTime)
                            }
                            if (_this.resizeHandle) {
                                let obj = {
                                    taskId,
                                    startTime: $(ui.helper[0]).attr('starttime'),
                                    endTime: $(ui.helper[0]).attr('endtime')
                                    
                                }
                                // 拉伸计划
                                _this.resizeHandle(obj)
                            }

                            isDragFlg = false
                        }
                    })
                }
                if (isDrag === 'true') {
                    $(this).draggable({
                        containment: ".taskline" + parentId,
                        axis: 'x',
                        grid: [_this.tableRowWidth, 15],
                        drag: function (event, ui) {
                            let rateW = $('.rateDiv' + taskId).width()
                            $('.drapBox' + taskId).css('left', ui.position.left + 'px')
                            isDragFlg = true
                        }, stop: function (event, ui) {
                            if (_this.showType != 'day') {
                                if ((ui.position.left - ui.originalPosition.left) != 0) {
                                    let setLeft = ''
                                    /* 拖动后紧贴边----start*/
                                    if (ui.position.left % _this.tableRowWidth > _this.tableRowWidth / 2) {
                                        setLeft = Math.floor(ui.position.left / _this.tableRowWidth) * _this.tableRowWidth + _this.tableRowWidth
                                    } else {
                                        setLeft = Math.floor(ui.position.left / _this.tableRowWidth) * _this.tableRowWidth
                                    }
                                    if (setLeft < 0) {
                                        setLeft = 0
                                    }

                                    let taskWidth = $(ui.helper[0]).css('width').replace('px', '')
                                    let allWidth = parseFloat(taskWidth) + setLeft
                                    // 不能超出页面最右侧的日期，紧贴最右侧
                                    let containerWidth = $('.taskline').css('width').replace('px', '')
                                    let diff = 0
                                    if (allWidth > containerWidth) {
                                        diff = allWidth - containerWidth + 1
                                    }
                                    $(ui.helper[0]).css('left', setLeft - diff)
                                    // 更新进度条拖动图标位置
                                    $('.drapBox' + taskId).css('left', setLeft - diff)
                                    /* 拖动后紧贴边----end*/
                                    // 计算拖动后的日期
                                    let oldStartTime = $(ui.helper[0]).attr('starttime')
                                    let oldEndTime = $(ui.helper[0]).attr('endtime')
                                    let oldDiffDays = getDaysBetween(oldStartTime, oldEndTime)
                                    let curStartTime, curEndTime
                                    if (_this.showType == 'month') {
                                        if (diff != 0) {
                                            // 超出右侧是进度条尾部贴着线
                                            curStartTime = formatDateDorward(maxMonthDate, -oldDiffDays)
                                            curEndTime = maxMonthDate
                                        } else {
                                            // 不超出右侧
                                            // 距离前面有几个月,3列为一个月,1列为10天
                                            curStartTime = addMonths(minMonthDate, Math.floor((setLeft - diff) / _this.tableRowWidth / 3)).substring(0, 7)
                                            let duochuCol = (setLeft - diff) / _this.tableRowWidth % 3

                                            if (duochuCol == 0) {
                                                curStartTime = curStartTime + '-' + '01'
                                            } else if (duochuCol == 1) {
                                                curStartTime = curStartTime + '-' + '11'
                                            } else if (duochuCol == 2) {
                                                curStartTime = curStartTime + '-' + '21'
                                            }
                                            curEndTime = formatDateDorward(curStartTime, oldDiffDays)
                                        }
                                    } else if (_this.showType == 'jidu') {
                                        if (diff != 0) {
                                            // 超出右侧是进度条尾部贴着线
                                            curStartTime = formatDateDorward(jiduMaxDate, -oldDiffDays)
                                            curEndTime = jiduMaxDate
                                        } else {
                                            // 不超出右侧
                                            // 距离前面有几个月,3列为一个季度,1列一个月
                                            curStartTime = addMonths(jiduMinDate, Math.floor((setLeft - diff) / _this.tableRowWidth)).substring(0, 7)
                                            curStartTime = curStartTime + '-' + '01'
                                            curEndTime = formatDateDorward(curStartTime, oldDiffDays)
                                        }
                                    } else if (_this.showType == 'year') {

                                        if (diff != 0) {
                                            // 超出右侧是进度条尾部贴着线
                                            curStartTime = formatDateDorward(maxYearDate, -oldDiffDays)
                                            curEndTime = maxYearDate
                                        } else {
                                            // 不超出右侧
                                            // 距离前面有几个月,1列一个月
                                            curStartTime = addMonths(minYearDate, Math.floor((setLeft - diff) / _this.tableRowWidth)).substring(0, 7)
                                            curStartTime = curStartTime + '-' + '01'
                                            curEndTime = formatDateDorward(curStartTime, oldDiffDays)
                                        }
                                    }
                                    $(this).attr('starttime', curStartTime)
                                    $(this).attr('endtime', curEndTime)
                                }
                            } else {
                                if ((ui.position.left - ui.originalPosition.left) != 0) {
                                    // 拖动了
                                    let dragJL = Number((ui.position.left - ui.originalPosition.left) / _this.tableRowWidth)
                                    let myStartTime = $(this).attr('starttime')
                                    let myEndTime = $(this).attr('endtime')
                                    let curStartTime = formatDateDorward(myStartTime, dragJL)
                                    let curEndTime = formatDateDorward(myEndTime, dragJL)

                                    // 拖动后实际的开始时间结束时间存起来
                                    $(this).attr('starttime', curStartTime)
                                    $(this).attr('endtime', curEndTime)
                                }
                            }
                            if (_this.dragHandle) {
                                let obj = {
                                    taskId: $(this).attr('taskid'),
                                    startTime: $(this).attr('starttime'),
                                    endTime: $(this).attr('endtime')
                                }
                                // 拖动计划
                                _this.dragHandle(obj)
                            }
                            isDragFlg = false
                        }
                    })
                }
            })
            // 表格滚动监听
            _this.$ele.find("#mainTable").on('scroll', function () {
                var a = this.scrollTop;
                var b = this.scrollLeft;
                _this.$ele.find("#dateTable").css("left", -b + 'px');
            })
        },
        fnPage(datas, parentId) {
            //渲染右侧进度
            var _this = this
            datas.forEach(item => {
                // 左侧任务
                let leftbodyHtml = '', rightDataHtml = '', left_Col_html = '';
                // 展示2列单位
                if (this.leftShowColNum == 2) {
                    left_Col_html = `
                        <div class="threeCol" title="${item.participateOrgName}">
                            <span>${item.participateOrgName}</span>
                        </div>`;
                }
                // gantt图修改js
                leftbodyHtml += `<div class="node">
									<div class="node-title ${item.level == 1 ? 'firstNode' : ''} 
										nodeTitle${item.id}" id='${item.id}' level="${item.level}"
                                        parentid="${item.parentId}" processstatus="${item.processStatus}">
										<div class="firstCol">
											<span class="gantt_handle_btn ${item.children && item.children.length > 0 ? 'addPicZK' : ''}" 
												title="${item.projectTitle}"
												data-type="${item.type}"
												auth-edit="${item.edit}"
												auth-audit="${item.audit}">${item.projectTitle}</span>
										</div>
										<div class="twoCol" title="${item.chargeOrgName}">
											<span">${item.chargeOrgName}</span>
										</div>
                                        ${left_Col_html}
									</div>`
                if (item.children && item.children.length > 0) {
                    leftbodyHtml += `<div class="node-children node-children${item.id} nodeLevel${item.level} showModel${item.id}"></div>`
                }
                leftbodyHtml += `</div>`

                if (parentId == '') {
                    $('#treeTable').append(leftbodyHtml)
                } else {
                    $('.node-children' + parentId).append(leftbodyHtml)
                }

                let taskLineTop = $('.nodeTitle' + item.id)[0].offsetTop
                // 每一级下的任务用一个div包起来,折叠展开用
                if (item.level == 2) {
                    rightDataHtml += `<div class="showModel${parentId}">`
                }
                rightDataHtml += `<div style="position:relative;width: 100%;height: 25px;" parentId="${item.id}" class="taskline taskline${item.id}">`
                // 渲染进度条
                if (item.taskList && item.taskList.length > 0) {
                    // 进度条颜色值转化
                    let taskColorBg = hexToRgb(_this.taskColor, _this.taskOpacity)//进度条背景色
                    let rateColorBg = hexToRgb(_this.rateColor, _this.rateOpacity)//进度条进度颜色

                    item.taskList.forEach(subItem => {
                        let divLeft, rateWidth, divWidth
                        let obj = _this.computePosition(subItem) // gantt图修改js
                        // 进度条颜色值转化
                        if (!!subItem.taskColor) {
                            taskColorBg = hexToRgb(subItem.taskColor, _this.taskOpacity)//进度条背景色
                        }
                        if (!!subItem.rateColor) {
                            rateColorBg = hexToRgb(subItem.rateColor, _this.rateOpacity)//进度条进度颜色
                        }
                        // let daysF=getDaysBetween(mfdSTime,subItem.startTime)
                        divLeft = obj.divLeft
                        divWidth = obj.divWidth

                        rateWidth = divWidth * subItem.rate / 100
                        if (subItem.isIcon) {
                            let iconUrl = '/plugins/ganttCustom/daysanjiao.png'
                            if (subItem.iconType == 1) {//三角形
                                iconUrl = '/plugins/ganttCustom/daysanjiao.png'
                            }
                            // 三角形一半宽度是7
                            if (_this.showType == 'day') {
                                divLeft = divLeft + _this.tableRowWidth / 2 - 7
                            } else {
                                divLeft = divLeft - 7
                            }
                            rightDataHtml += `<div class="oneNodeImg oneNodeImg${subItem.id}" isdrag="${subItem.isDrag}" date="${subItem.startTime}" taskname="${subItem.name}" taskId="${subItem.id}" parentId="${item.id}" style="width:14px;height:25px;line-height:25px;left:${divLeft}px">
											<img class="imgNode" src="${iconUrl}" style="width:14px;height:14px;">
											</div>`
                        } else {
                            // =============== 重大任务  - 总体进度 - 右侧甘特图进度上展示图标    start ==========
                            /* LEAD_UNIT_BE_PROGRESS_UPDATE("10", "待更新"),
                            LEAD_UNIT_BE_PROGRESS_UPDATE_REJECT("10-1", "待更新(被驳回)"),
                            LEAD_UNIT_BE_PROGRESS_UPDATE_SUBMIT("10-2", "已修改(待提交)"),
                            LEAD_UNIT_BE_PROGRESS_APPROVE("11", "待审核"),
                            PLAN_COMPLETED("12","总计划完成结束") */
                            let icon_str = '';
                            if (subItem.processStatus == "10-1") {
                                icon_str += `<div class="Overall_progress be_rejected"></div>`;
                            } else if (subItem.processStatus == "10-2") {
                                icon_str += `<div class="Overall_progress Modified_to_be_submitted"></div>`;
                            } else if (subItem.processStatus == "11") {
                                icon_str += `<div class="Overall_progress">
                                                <i class="layui-icon layui-icon-friends"></i>
                                            </div>`;
                            }
                            // =============== 重大任务  - 总体进度 - 右侧甘特图进度上展示图标    end   ==========

                            let rate_div_html = `<div class="rateDiv rateDiv${subItem.id}" 
													taskId="${subItem.id}" oldrate="${subItem.rate}" 
													style="width:${rateWidth}px;background:${rateColorBg}"></div>`;
                            let data_content_html = subItem.name + '   ' + (subItem.rate ? subItem.rate + '%' : '');
                            // =============== 重大专项  - 项目计划 - 右侧内部不展示实际进度条    start   ==========
                            console.log('isShowRateDiv----', _this.isShowRateDiv)
                            if (_this.isShowRateDiv == 2) {
                                rate_div_html = '';
                                data_content_html = subItem.name;
                            }
                            // =============== 重大专项  - 项目计划 - 右侧甘特图进度上展示图标    end   ==========
                            rightDataHtml += `<div class="taskDiv taskDiv${subItem.id}"
												parentId="${item.id}"
												isdrag="${subItem.isDrag}" isresize="${subItem.isResize}" 
												taskname="${subItem.name}" title="${subItem.name}" 
												data-content="${data_content_html}"
												starttime="${subItem.startTime}" endtime="${subItem.endTime}" 
												taskId="${subItem.id}"
												progressId="${subItem.progressId}"
												auth-add="${subItem.add}"
												auth-edit="${subItem.edit}" 
												auth-audit="${subItem.audit}"
												style="left:${divLeft}px;width:${divWidth}px;background:${taskColorBg}">
												${ rate_div_html }
                                                ${ icon_str }
											</div>
											`
                            // 拖动进度条隐藏
                            // <div class="drapBox drapBox${subItem.id}" taskId='${subItem.id}' style="width:${divWidth+7}px;left:${divLeft}px;">
                            // 	<div class="task_progress_drag task_progress_drag${subItem.id}" taskId="${subItem.id}"></div>
                            // </div>
                        }

                    })
                }
                rightDataHtml += `</div>`
                if (item.level != 1 && item.children && item.children.length > 0) {
                    rightDataHtml += `<div class="rightChildren${item.id}"></div>`
                }
                if (item.level == 2) {
                    rightDataHtml += `</div>`
                }

                if (item.level < 3) {
                    $('#dataList').append(rightDataHtml)
                } else {
                    $('.rightChildren' + parentId).append(rightDataHtml)
                    $('.rightChildren' + parentId).addClass('showModel' + parentId)
                }

                if (item.children && item.children.length > 0) {
                    _this.fnPage(item.children, item.id)
                }
            })

        },
        computePosition(item) {
            /*
			item就是进度条的信息
			*/
            let _this = this
            let divLeft, divWidth
            // 计算进度条宽度及位置和进度宽度
            if (_this.showType == 'day') {
                let daysF = getDaysBetween(_this.startTime, item.startTime)
                divLeft = daysF * _this.tableRowWidth
                divWidth = getDaysBetween(item.startTime, item.endTime) * _this.tableRowWidth + _this.tableRowWidth
                if (_this.startTime == item.startTime) {
                    divLeft = 0
                }
            } else if (_this.showType == 'month') {
                // 一个月是3列,每列30px,开始时间相对右侧最左侧距离
                let diffMonths = reduMonths(_this.startTime, item.startTime)
                let juliLeftByDiffMonth = diffMonths * 3 * _this.tableRowWidth

                // 当前开始日期月份有多少天
                let startMonthHasDays = getDaysInMonth(item.startTime)
                // 计算当前日占当月宽度多少
                let curDay = Number(item.startTime.substring(8, 11))
                divLeft = juliLeftByDiffMonth + _this.tableRowWidth * 3 * curDay / startMonthHasDays

                // 计算当前月的天数占的宽度，包含当天
                let startWidth = _this.tableRowWidth * 3 * (startMonthHasDays - curDay + 1) / startMonthHasDays
                // 宽度是取整月就是diffCurMonths*3*_this.tableRowWidth,开始和结束月按当月天数计算占比宽度

                let diffCurMonths = reduMonths(item.startTime, item.endTime) - 1

                // 当前结束日期月份有多少天
                let endMonthHasDays = getDaysInMonth(item.endTime)
                // 计算结束日占当月宽度多少
                let endDay = Number(item.endTime.substring(8, 11))
                let endDateWidth = _this.tableRowWidth * 3 * endDay / endMonthHasDays
                divWidth = startWidth + diffCurMonths * 3 * _this.tableRowWidth + endDateWidth
                if (minMonthDate == item.startTime) {
                    divLeft = 0
                }
            } else if (_this.showType == 'jidu') {
                let diffMonths = reduMonths(jiduMinDate, item.startTime)
                let juliLeftByDiffMonth = diffMonths * _this.tableRowWidth
                // 当前开始日期月份有多少天
                let startMonthHasDays = getDaysInMonth(item.startTime)
                // 计算当前日占当月宽度多少
                let curDay = Number(item.startTime.substring(8, 11))
                divLeft = juliLeftByDiffMonth + _this.tableRowWidth * curDay / startMonthHasDays

                // 计算当前月的天数占的宽度，包含当天
                let startWidth = _this.tableRowWidth * (startMonthHasDays - curDay + 1) / startMonthHasDays
                // 宽度是取整月就是diffCurMonths*_this.tableRowWidth,开始和结束月按当月天数计算占比宽度
                let diffCurMonths = reduMonths(item.startTime, item.endTime) - 1

                // 当前结束日期月份有多少天
                let endMonthHasDays = getDaysInMonth(item.endTime)
                // 计算结束日占当月宽度多少
                let endDay = Number(item.endTime.substring(8, 11))
                let endDateWidth = _this.tableRowWidth * endDay / endMonthHasDays
                divWidth = startWidth + diffCurMonths * _this.tableRowWidth + endDateWidth
                if (jiduMinDate == item.startTime) {
                    divLeft = 0
                }
            } else if (_this.showType == 'year') {
                // 每年有12列,筛选的开始年份
                let startYear = new Date(item.startTime).getFullYear()
                let endYear = new Date(item.endTime).getFullYear()
                // let startYearFirstDate = startYear + '-' + '01' + '-'+ '01'
                let startYearLastDate = startYear + '-' + '12' + '-' + '31'
                let endYearFirstDate = endYear + '-' + '01' + '-' + '01'
                let minYear = new Date(_this.startTime).getFullYear()
                let minDate = minYear + '-' + '01' + '-' + '01'
                // 两个日期包含年份
                let diffYears = getYearsInRange(minDate, item.startTime)

                let fullYearsNum = diffYears.length - 1
                // 计算距离左侧距离
                // let diffDaysStart = getDaysBetween(startYearFirstDate,item.startTime)

                let curYearDaysStart = daysInYear(item.startTime)

                // let juliLeftStart = 12*_this.tableRowWidth/curYearDaysStart*diffDaysStart
                // divLeft = fullYearsNum*12*_this.tableRowWidth + juliLeftStart
                // 图标时,上面的算法 会有偏移
                let diffMonths = reduMonths(item.startTime, minDate)
                let curMonthHasDays = getDaysInMonth(item.startTime)
                let curDay = Number(item.startTime.substring(8, 10))
                divLeft = diffMonths * _this.tableRowWidth + curDay * _this.tableRowWidth / curMonthHasDays

                // 计算开始日期和结束日期所在年份占比例
                // 开始日期结束日期不在同一年
                if (startYear != endYear) {
                    let startDiffs = getDaysBetween(item.startTime, startYearLastDate)
                    let startYearWidth = 12 * _this.tableRowWidth * startDiffs / curYearDaysStart
                    let endDiffs = getDaysBetween(item.endTime, endYearFirstDate)
                    let curYearDaysEnd = daysInYear(item.startTime)
                    let endYearWidth = 12 * _this.tableRowWidth / curYearDaysEnd * endDiffs
                    divWidth = (fullYearsNum - 1) * 12 * _this.tableRowWidth + startYearWidth + endYearWidth
                } else {
                    let diffDaysStartAndEnd = getDaysBetween(item.startTime, item.endTime)
                    divWidth = 12 * _this.tableRowWidth / curYearDaysStart * diffDaysStartAndEnd
                }
                if (minYearDate == item.startTime) {
                    divLeft = 0
                }
            }

            if (item.startTime == item.endTime) {
                divWidth = _this.tableRowWidth
            }
            return {divLeft: divLeft, divWidth: divWidth}
        }
    }


    function getDateFn(item) {
        item.forEach(fItem => {
            if (fItem.taskList && fItem.taskList.length > 0) {
                fItem.taskList.forEach(subItem => {
                    startDateAll.push(subItem.startTime)
                    endDateAll.push(subItem.endTime)
                })
            }
            if (fItem.children && fItem.children.length > 0) {
                getDateFn(fItem.children)
            }
        })


    }


    // 显示隐藏多列
    window.changeCol = function (e) {
        let src = $(e.currentTarget).attr('src')
        let colnum = $('#mainGanttBox').attr('colnum');
        if (src.indexOf('qh2') != -1) {
            $(e.currentTarget).attr('src', '/plugins/ganttCustom/qh.png')
            $('.timeTitle').hide()
            $('.twoCol').hide()
            $('.threeCol').hide()

            $('.tableTitle').css('width', 200)
            $('.leftTable').css('width', 200)
            $('#rightTable').css('width', 'calc(100% - 200px)')
            $(e.currentTarget).css('left', '191px')
        } else {
            $(e.currentTarget).attr('src', '/plugins/ganttCustom/qh2.png')
            $('.timeTitle').show()
            $('.twoCol').show()
            $('.threeCol').show()

            // 展示2列单位
            if (colnum == 2) {
                $('.tableTitle').css('width',453)
                $('.leftTable').css('width',453)
                $('#rightTable').css('width','calc(100% - 453px)')
                $(e.currentTarget).css('left','446px')
            } else {
                $('.tableTitle').css('width', 400)
                $('.leftTable').css('width', 400)
                $('#rightTable').css('width', 'calc(100% - 400px)')
                $(e.currentTarget).css('left', '393px')
            }

        }
        // 重新渲染表格
        // this.reLoad()
    }

    /**
     * 获取日期为年的第几周  周首日为周日
     * @param str
     * @returns {string}
     */
    function getWeekNum(str) {
        let temptTime = new Date(str)
        //周首日是周一
        // let weekday = temptTime.getDay() || 7
        //周首日是周日
        let weekday = temptTime.getDay()
        //周1+5天=周六
        temptTime.setDate(temptTime.getDate() - weekday + 1 + 5)
        let firstDay = new Date(temptTime.getFullYear(), 0, 1)
        let dayOfWeek = firstDay.getDay()
        let spendDay = 1
        if (dayOfWeek != 0) {
            spendDay = 7 - dayOfWeek + 1
        }
        firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay)
        let d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000)
        let result = Math.ceil(d / 7)
        var week = result + 1;
        var year = temptTime.getFullYear();
        return year + "-" + week;
    }

    //根据日期获取星期
    function getWeek(date) {
        var day = new Date(Date.parse(date));
        var today = ['日', '一', '二', '三', '四', '五', '六'];
        return today[day.getDay()];
    }

    // 获取日期区间内每一天
    function getDiffDate(start, end) {

        var startTime = getDate(start);

        var endTime = getDate(end);

        var dateArr = [];

        while ((endTime.getTime() - startTime.getTime()) >= 0) {

            var year = startTime.getFullYear();
            var month = (startTime.getMonth() + 1).toString().length === 1 ? "0" + (parseInt(startTime.getMonth()
                .toString(), 10) + 1) : (startTime.getMonth() + 1);

            var day = startTime.getDate().toString().length === 1 ? "0" + startTime.getDate() : startTime.getDate();

            dateArr.push(year + "-" + month + "-" + day);

            startTime.setDate(startTime.getDate() + 1);

        }

        return dateArr;

    }

    function getDate(datestr) {

        var temp = datestr.split("-");

        if (temp[1] === '01') {

            temp[0] = parseInt(temp[0], 10) - 1;

            temp[1] = '12';

        } else {

            temp[1] = parseInt(temp[1], 10) - 1;

        }

        //new Date()的月份入参实际都是当前值-1

        var date = new Date(temp[0], temp[1], temp[2]);

        return date;

    }

    // 获取月
    // startDate 2022-01-26
    // endDate 2022-04-26

    function getMonth(start, end) {
        var result = []
        var s = start.split('-')
        var e = end.split('-')
        var min = new Date()
        var max = new Date()
        min.setFullYear(s[0], s[1] * 1 - 1, 1) //开始日期

        max.setFullYear(e[0], e[1] * 1 - 1, 1) //结束日期
        var curr = min
        while (curr <= max) {
            var month = curr.getMonth()
            result.push(formatDate(curr, 'yyyy-MM'))
            curr.setMonth(month + 1)
        }
        return result
    }

    // 格式化日期
    function formatDate(oldDate, format = 'yyyy-MM-dd HH:mm:ss') {
        const date = new Date(oldDate)
        const config = {
            yyyy: date.getFullYear(),
            M: date.getMonth() + 1,
            MM: formatNum(date.getMonth() + 1),
            W: date.getDay(),
            WW: formatNum(date.getDay()),
            d: date.getDate(),
            dd: formatNum(date.getDate()),
            H: date.getHours(),
            HH: formatNum(date.getHours()),
            h: date.getHours() > 12 ? (date.getHours() - 12) : date.getHours(),
            hh: formatNum(date.getHours()) > 12 ? (formatNum(date.getHours()) - 12) : formatNum(date.getHours()),
            m: date.getMinutes(),
            mm: formatNum(date.getMinutes()),
            s: date.getSeconds(),
            ss: formatNum(date.getSeconds()),
            A: date.getHours() < 12 ? 'AM' : 'PM',
            a: date.getHours() < 12 ? 'am' : 'pm'
        }
        const formatConfigs = format.match(/[a-zA-Z]+/g)
        formatConfigs.forEach(item => {
            format = format.replace(item, config[item])
        })
        return format
    }

    function formatNum(num) {
        return num < 10 ? `0${num}` : num
    }

    // 获取周
    // startDate 2022-03-26
    // endDate 2022-04-26
    function getWeak(start, end) {
        // 1、获取开始日期属于第几周，哪年
        let startWeekNum = this.getWeekNum(start)
        let startYearNum = parseInt(start.split('-')[0])

        if (startWeekNum >= 53) {
            startWeekNum = 52
        }

        // 2、获取结束日期属于第几周，哪年
        let endWeekNum = this.getWeekNum(end)
        let endYearNum = parseInt(end.split('-')[0])

        if (endWeekNum >= 53) {
            endWeekNum = 52
        }

        // 3、计算周数
        let result = []
        let yearAdd = 0 // 跨年数
        let yearWeekNum = startWeekNum // 当前取到的周数
        for (let i = 0; i <= (endYearNum - startYearNum) * 52 - startWeekNum + endWeekNum; i++) {
            if ((startWeekNum + i) <= 0) { // 如果开始周数是0，则取开始年上一年的52周
                result.push((startYearNum - 1) + "52")
            } else {
                if (yearWeekNum === 52) {
                    yearAdd++
                }
                yearWeekNum = startWeekNum + i - yearAdd * 52
                if (yearWeekNum <= 0) { // 如果开始周数是0，则取开始年上一年的52周
                    result.push(startYearNum + "52")
                } else {
                    // if (yearWeekNum < 10){
                    //   result.push((startYearNum + yearAdd) + "0" + yearWeekNum)
                    // }else {
                    result.push((startYearNum + yearAdd) + "" + yearWeekNum)
                    // }
                }
            }
        }
        return result
    }

    function getWeekNum(dt) {
        let d1 = new Date(dt);
        let d2 = new Date(dt);
        d2.setMonth(0);
        d2.setDate(1);
        let rq = d1 - d2;
        let days = Math.ceil(rq / (24 * 60 * 60 * 1000));
        let num = Math.ceil(days / 7);
        return num;
    }

    /**
     * 计算两个日期之间的天数
     * @param dateString1  开始日期 yyyy-MM-dd
     * @param dateString2  结束日期 yyyy-MM-dd
     * @returns {number} 如果日期相同 返回一天 开始日期大于结束日期，返回0
     */
    function getDaysBetween(dateString1, dateString2) {
        var startDate = Date.parse(dateString1);
        var endDate = Date.parse(dateString2);
        if (startDate > endDate) {
            return 0;
        }
        if (startDate == endDate) {
            return 1;
        }
        var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
        return days;
    }

    // 两个日期之间的月份差
    function reduMonths(startMonth, endMonth) {
        let startY = startMonth.split("-")[0],
            startM = startMonth.split("-")[1],
            endY = endMonth.split("-")[0],
            endM = endMonth.split("-")[1];
        startMonth = startY + startM
        endMonth = endY + endM
        if (startMonth > endMonth) {
            let reduY = startY - endY,
                reduM = startM - endM;
            return reduY * 12 + reduM
        } else if (startMonth < endMonth) {
            let reduY = endY - startY,
                reduM = endM - startM;

            return reduY * 12 + reduM
        } else {
            return 0
        }
    }

    function getYearsInRange(startDate, endDate) {
        let years = []
        let currentYear = new Date(startDate).getFullYear()
        while (currentYear <= new Date(endDate).getFullYear()) {
            years.push(currentYear)
            currentYear++
        }
        return years
    }

    // 日期比大小,返回小的日期
    function compareDate(dateTime1, dateTime2) {
        var formatDate1 = new Date(dateTime1)
        var formatDate2 = new Date(dateTime2)
        if (formatDate1 < formatDate2) {
            // return formatDate(formatDate1,'yyyy-MM-dd');
            return -1
        } else {
            // return formatDate(formatDate2,'yyyy-MM-dd');
            return 1
        }
    }

    //当前日期往前推n天就传负数如-3，往后推就传正数如3
    function formatDateDorward(cuDate, n) {
        let date = new Date(cuDate)
        date.setDate(date.getDate() + n)
        let y = date.getFullYear()
        let m = date.getMonth() + 1
        let day = date.getDate()
        m = m < 10 ? '0' + m : m
        day = day < 10 ? '0' + day : day
        return y + '-' + m + '-' + day
    }

    // 加月份
    function addMonths(date, months) {
        var newDate = new Date(date)
        newDate.setMonth(newDate.getMonth() + months)

        return formatDate(newDate, 'yyyy-MM-dd')
    }

    // 最大值

    function getDateMax(dataArr) {
        let max = dataArr[0];
        for (let i = 1; i < dataArr.length; i++) {
            if (Date.parse(dataArr[i]) > Date.parse(max)) {
                max = dataArr[i]
            }
        }
        return max
    }

    // 最小值

    function getDateMin(dataArr) {
        let min = dataArr[0];
        for (let i = 1; i < dataArr.length; i++) {
            if (Date.parse(dataArr[i]) < Date.parse(min)) {
                min = dataArr[i]
            }
        }
        return min
    }

    // 一年有多少天
    function daysInYear(date) {
        let year = new Date(date).getFullYear()
        if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
            return 366
        } else {
            return 365
        }
    }

    // 给定月份有多少天
    function getDaysInMonth(date) {
        let year = new Date(date).getFullYear()
        let month = new Date(date).getMonth()
        return new Date(year, month + 1, 0).getDate()
    }

    // 获取给定日期月份的第一天
    function currentTime(curdate) {
        const currentDate = new Date(curdate)
        const year = currentDate.getFullYear()
        const month = string(currentDate.getMonth() + 1).padStart(2, "0")
        const firstDay = "01"
        return `${year}-${month}-${firstDay}`
    }

    // 获取给定日期月份的最后一天
    function getLastdayOfMonth(curDate) {
        const currentDate = new Date(curdate)
        let year = currentDate.getFullYear()
        let month = string(currentDate.getMonth() + 2).padStart(2, "0")
        if (month === '13') {
            year = year + 1
            month = '01'
        }
        let firstDay = "01"
        const firstDayOfNextMonth = `${year}-${month}-${firstDay}`
        const lastDayOfMonth = new Date(new Date(firstDayOfNextMonth).getTime() - 86400000)
        return lastDayOfMonth.toISOString().split('T')[0]
    }

    // 日期减n天后的日期
    function dateDelDays(dateStr, dayCount) {
        if (!!dateStr) {
            var tempDate = new Date(dateStr.replace(/-/g, "/"));//把日期字符串转换成日期格式
            var resultDate = new Date((tempDate / 1000 - (86400 * dayCount)) * 1000);//减n天后的日期
            var resultDateStr = resultDate.getFullYear() + "-" + (resultDate.getMonth() + 1 < 10 ? '0' + (resultDate.getMonth() + 1) : resultDate.getMonth() + 1) + "-" + (resultDate.getDate() < 10 ? '0' + resultDate.getDate() : resultDate.getDate());//将日期转化为字符串格式
            return resultDateStr;
        }
    }

    function nextMonthEndday() {
        // 日期为空就赋值当前月的第一天到下个月的最后一天
        var date = new Date();
        var nowYear = date.getFullYear();
        var month = date.getMonth() + 1;
        var month2 = "";
        if (month < 10) {
            month = "0" + month;
        }
        //上一月
        var month1 = month + '-01';
        //下一月
        if (date.getMonth() + 2 < 10) {
            month2 = "0" + (date.getMonth() + 2);
        } else {
            month2 = (date.getMonth() + 2);
        }
        if (month2 > 12) {
            //超过12月 年份进1
            month2 = month2 - 12;
            nowYear2 = parseInt(nowYear) + 1;
        } else {
            nowYear2 = nowYear;
        }
        //获取当前月天数
        var days = new Date(nowYear2, month2, 0);
        return nowYear2 + '-' + month2 + '-' + days.getDate();
    }

    // 获取当前日期
    function getCurrentDay() {
        var now = new Date()
        var year = now.getFullYear();//获取当前年份
        var month = now.getMonth() + 1;//当前月份
        if (month < 10)
            month = "0" + month;
        else {
            month = month;
        }
        var day = now.getDate();//当前天份

        if (day < 10)
            day = "0" + day;
        else {
            day = day;
        }

        return year + "-" + month + "-" + day;
    }

    // 颜色十六进制转rgba
    function hexToRgb(hex, opacity, type) {
        // 确保我们有一个有效的十六进制字符串
        hex = hex.replace('#', '');
        if (hex.length !== 6) {
            throw new Error('Invalid HEX color');
        }

        // 将十六进制转换为十进制
        var r = parseInt(hex.substring(0, 2), 16);
        var g = parseInt(hex.substring(2, 4), 16);
        var b = parseInt(hex.substring(4, 6), 16);
        if (type == 1) {
            r = r + 20
            g = g + 30
            b = b + 30
        }
        return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + opacity + ')';
    }

    if (typeof exports == "object") {
        module.exports = GanttCustom;
    } else if (typeof define == "function" && define.amd) {
        define([], function () {
            return GanttCustom;
        })
    } else {
        window.GanttCustom = GanttCustom;
    }
})();
